package com.txc.pay.service.impl;


import com.txc.pay.pay.ThirdPay;
import com.txc.pay.service.IAccountService;
import com.txc.pay.service.IThirdPayService;
import com.txc.pay.vo.OrderVo;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.Map;
import java.util.Objects;

import static com.txc.pay.enums.PayMethodEnum.getEnum;


/**
 * @ClassName: IThirdPayServiceImpl
 * @Description:
 * @Author: TXC
 * @Date: 2023-12-26 09:59
 **/
@Service
public class IThirdPayServiceImpl implements IThirdPayService {
    @Resource
    private IAccountService accountService;
    @Resource
    private Map<String, ThirdPay> thirdPayMap;

    private ThirdPay getPayService(String type, String method) {
        return thirdPayMap.get(Objects.requireNonNull(getEnum(type, method)).getService());
    }

    @Override
    public String thirdPay(String type, String method, OrderVo order) {
        return getPayService(type, method).pay(order);
    }

    @Override
    public String refund(String type, String method, String outRefundNo, String refund, String total,
                         String accountId) {
        return getPayService(type, method).refund(outRefundNo, refund, total, accountId);
    }

    @Override
    public String queryByOutRefundNo(String type, String method, String outRefundNo, String accountId) {
        return getPayService(type, method).queryByOutRefundNo(outRefundNo, accountId);
    }

    @Override
    public String queryOrderById(String type, String method, String transactionId, String accountId) {
        return getPayService(type, method).queryOrderById(transactionId, accountId);
    }

    @Override
    public String queryOrderByOutTradeNo(String type, String method, String outTradeNo, String accountId) {
        return getPayService(type, method).queryOrderByOutTradeNo(outTradeNo, accountId);
    }

    @Override
    public String closeOrder(String type, String method, String outTradeNo, String accountId) {
        return getPayService(type, method).closeOrder(outTradeNo, accountId);
    }

}
